<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/layout/common.xhtml">
	<ui:define name="body">
		<h:form id="form" acceptcharset="ISO-8859-1">
			<f:metadata>
				<f:viewParam name="param" value="#{associarBean.param}"/>
			</f:metadata>
		
			<p:panel header="#{msg['massai.associacao.header']}">
				<h:panelGrid>
					<h:panelGrid rendered="#{associarBean.obra.id ne null}" style="margin: 0 0 5px 0;">
						<h:panelGroup>
							<p:selectBooleanCheckbox tabindex="1" label="#{msg['massai.associacao.bloquearObra']}" value="#{associarBean.status}">
								<p:ajax event="change" global="false" />
							</p:selectBooleanCheckbox>
							<p:outputLabel value="#{msg['massai.associacao.bloquearObra']}" style="padding: 0 0 3px 5px;" />
						</h:panelGroup>
					</h:panelGrid>
				</h:panelGrid>

				<h:panelGrid columns="4">
					<h:panelGrid>
						<p:outputLabel value="#{msg['massai.associacao.codigoColigada']}" for="coligada" />
						<p:inputText tabindex="2" required="true" requiredMessage="#{msg['massai.associacao.codigoColigada']} é obrigatório(a)."
							value="#{associarBean.codColigada}" id="coligada" style="width: 60px; text-align: right;"
							onkeypress="return numberOnly(this, event);" label="#{msg['massai.associacao.codigoColigada']}">
							<p:ajax event="change" listener="#{associarBean.pesquisaObraTotvs()}" update="form,:messages" />
						</p:inputText>
					</h:panelGrid>

					<h:panelGrid>
						<p:outputLabel value="#{msg['massai.associacao.codigoTotvs']}" for="codDepto" />
						<p:inputMask tabindex="3" mask="999.99.9.999" id="codDepto"
							value="#{associarBean.codDepto}" required="true"
							requiredMessage="#{msg['massai.associacao.codigoTotvs']} é obrigatório(a)."
							style="width: 100px; text-align: right;">
							<p:ajax event="change" listener="#{associarBean.pesquisaObraTotvs()}" update="form,:messages" />
						</p:inputMask>
					</h:panelGrid>

					<h:panelGrid>
						<p:outputLabel value="#{msg['massai.associacao.codigoSienge']}" for="codSienge" />
						<p:inputText tabindex="4"
							style="width: 80px; text-align: right;" required="true"
							requiredMessage="#{msg['massai.associacao.codigoSienge']} é obrigatório(a)."
							value="#{associarBean.codigoSienge}" id="codSienge" 
							onkeypress="return numberOnly(this, event);">
						</p:inputText>
					</h:panelGrid>
				</h:panelGrid>

				<h:panelGrid>
					<h:panelGrid>
						<h:outputText value="#{msg['massai.associacao.nomeObraTotvs']}" />
						<p:inputText value="#{associarBean.nomeObra}" 
							disabled="true" readonly="true" style="width: 345px;" />
					</h:panelGrid>
				</h:panelGrid>

				<h:panelGrid>
					<h:panelGrid>
						<h:outputText value="#{msg['massai.associacao.nomeAssociacao']}" />
						<p:inputText tabindex="5" value="#{associarBean.nomeObraAssociacao}" style="width: 345px;">
						</p:inputText>
					</h:panelGrid>
				</h:panelGrid>

				<h:panelGrid columns="2">
					<h:panelGrid>
						<p:outputLabel value="#{msg['massai.associacao.colaborador']}" for="usuarios" />
						<p:selectOneMenu tabindex="6" value="#{associarBean.usuario}" 
							converter="entityConverter" style="width: 350px;" id="usuarios">
							<f:selectItems value="#{associarBean.usuarios()}" />
							<p:ajax global="false" event="change" />
						</p:selectOneMenu>
					</h:panelGrid>

					<h:panelGrid>
						<p:spacer height="14" />
						<p:commandButton tabindex="7" value="#{msg['massai.comum.adicionar']}" process="@form"
							ajax="true" actionListener="#{associarBean.adicionarResponsavel()}" 
							update="dataTableAssociacao,usuarios,form,:messages" />
					</h:panelGrid>
				</h:panelGrid>

				<p:dataTable id="dataTableAssociacao" style="margin-top: 15px;" emptyMessage="#{msg['massai.comum.emptyMessage']}" 
					value="#{associarBean.listaUsuariosAssociados}" var="user" sortMode="multiple" rows="10" paginator="true"
					paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
					currentPageReportTemplate="({currentPage} de {totalPages})" paginatorPosition="bottom" paginatorAlwaysVisible="false"
					rowIndexVar="row">

					<f:facet name="header"><h:outputText value="#{msg['massai.associacao.responsaveisAssociados']}" /></f:facet>

					<p:column headerText="#{msg['massai.itemServico.codigo']}" sortBy="#{user.id}" width="60">
						<h:outputText value="#{genericUtilBean.completarZerosEsquerda(user.id, 8)}" />
					</p:column>

					<p:column headerText="#{msg['massai.login.login']}" sortBy="#{user.login}" width="100">
						<h:outputText value="#{user.login}" />
					</p:column>

					<p:column headerText="#{msg['massai.associacao.nome']}" sortBy="#{user.nome}">
						<h:outputText value="#{user.nome}" />
					</p:column>
					
					<p:column headerText="#{msg['massai.usuario.email']}" sortBy="#{user.email}" width="180">
						<h:outputText value="#{user.email}" />
					</p:column>

					<p:column headerText="#{msg['massai.usuario.status']}" sortBy="#{user.ativo.descricao}" width="60">
						<h:outputText value="#{user.ativo.descricao}" />
					</p:column>

					<p:column headerText="#{msg['massai.comum.excluir']}" width="42" style="text-align: center;">
						<p:commandLink onclick="if (! window.confirm('Deseja excluir esse registro?') ) {return false}" 
							actionListener="#{associarBean.removerResponsavel(user, row)}" update=":form, :messages">
							<img src="#{facesContext.externalContext.requestContextPath}/imagens/ico_remove.png" 
								width="16" height="16" border="0" name="#{msg['massai.comum.excluir']}" 
								title="#{msg['massai.comum.excluir']}" alt="#{msg['massai.comum.excluir']}" />
						</p:commandLink>
					</p:column>
				</p:dataTable>

				<h:panelGrid width="100%">
					<h:panelGroup>
						<p:commandButton tabindex="8" value="#{msg['massai.comum.pesquisar']}" 
							ajax="false" immediate="true" action="associacao" 
							style="margin: 10px 10px 0 0;" />
							
						<p:commandButton tabindex="9" value="#{msg['massai.comum.novo']}" 
							action="associacaoCadastro" ajax="false" immediate="true"
							style="margin: 10px 10px 0 0;" />
					
						<p:commandButton tabindex="10" value="#{msg['massai.comum.salvar']}"
							actionListener="#{associarBean.salvar()}" ajax="false" 
							update="form,:messages" style="margin: 10px 0 0 0;" />
					</h:panelGroup>
				</h:panelGrid>
			</p:panel>
		</h:form>
	</ui:define>
</ui:composition>
</html>